<template>
  <div class="login">
    <hunk-head name="登陆"></hunk-head>
    <div class="login-content">
      <div class="login-text">
        <div>欢迎</div>
        <div>登陆老板账号</div>
      </div>
      <div class="login-form">
        <input type="text" name="number" placeholder="请输入老板账号" v-model="number">
        <input style="margin-top:10px;" maxlength="20" type="password" name="password" placeholder="请输入密码" v-model="password">
        <button class="login-btn" type="submit" @click="onSubmit">登 录</button>
      </div>
    </div>
    
  </div>
</template>

<script>
import Head from '@componentsMine/head'
import { bossLogin } from '@/apis/user'
import { setToken } from '@utils/auth'
import store from '@store/index'
export default {
  components: {
    'hunk-head': Head
  },
  data() {
    return {
      password: '',
      number: ''
    }  
  },
  computed: {
    userInfo(){
      return this.$store.state.baseStore.userInfo
    },
  },
  methods: {
    onSubmit() {
      if(!this.password){
        uni.showToast({
          title: '请输入密码！',
          icon: 'none'
        })
        return
      }
      if(!this.number){
        uni.showToast({
          title: '请输入账号！',
          icon: 'none'
        })
        return
      }
      const data = {
        userid: this.userInfo.userid,
        password: this.password,
        telphone: this.number
      }
      // uni.navigateTo({ url: "/pages/login/checkUser" })
      bossLogin(data).then(res=>{
        if(res.code == 200){
          uni.showToast({
            title: '老板登陆成功!'
          })
          wx.setStorageSync('sysUserInfo',JSON.stringify(res.data))
          console.log('老板登陆成功',res.data)
          setToken(res.data.token)
          store.commit('baseStore/SET_USERINFO', res.data)
          setTimeout(()=>{
            uni.redirectTo({ url: '/pages/index/index' })
            // that.$jump({path: '/pages/index/index'})
          },1000)
        }else{
          uni.showToast({
            title: res.msg,
            icon:'error'
          })
        }
        
      })
    }
  } 
}
</script>

<style lang="scss" scoped>
.login {
  @include num();
  background: #FFFFFF;
  padding-bottom: 50px;
  .login-content{
    box-sizing: border-box;
    padding: 40px 20px;
    .login-text{
      font-size: 20px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #000000;
      line-height: 26px;
    }
    .login-form{
      margin-top: 38px;
      input{
        height: 40px;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #000;
        line-height: 40px;
        border-bottom: 2px solid #EFEFEF;
      }
      input::placeholder{
        color: #9B9B9B;
      }
      .login-btn{
        margin-top: 20px;
        width: 335px;
        height: 45px;
        background: linear-gradient(315deg, #FFAA58 0%, #FFBD6C 100%);
        box-shadow: 0px 2px 4px 0px rgba(252, 156, 55, 0.21), 0px 3px 5px 0px rgba(255, 223, 111, 0.14);
        border-radius: 100px;
        font-size: 16px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #FFFFFF;
        line-height: 45px;
        text-align: center;
        text-shadow: 0px 2px 4px rgba(252, 156, 55, 0.21);
        border: 0;
      }
      .login-btn::after{
        border: 0;
      }
    }
  }
  
}
</style>
